<?php
/**
 * Matteo Vigoni <mattevigo@gmail.com>
 *
 * New blogpost script
 */
defined( "_ENTRY_" ) or die( "Restricted Access" );

import("core.Seed");
import( get_var('classpath', "post") );

$db = getDB();
$user = getUser( &$db );

$classpath = get_var( 'classpath', "post", NULL );

//print("Classpath: $classpath\n");

$location = "location: ";

$json = ""; // json message

// Seed and seeded Object
$seed = new Seed( &$db, NULL, NULL, get_var('seed_id', "post", NULL) );
$object = $seed->getObject( $classpath );

// Perform the action
try
{
	if( !$seed->isNew() )
	{
		$object->set('seed_id', $seed->getId());	//link the new object to the Seed
	}
	else
	{
		$seed->setUser( &$user );
		$seed->setClasspath( $classpath );
	}
	
	//if( count( $_GET ) > 0 ) $json = $object->doGet();

	if( count( $_POST ) > 0 ) $json = $object->doPost( &$user );
	
	// store the Seed and link the new object
	$seed->store();
	$object->setSeed( &$seed );

	var_dump($seed);
	var_dump($object);
	$object->store();
}
catch( Exception $e)
{
	$json = "{\"error\":\"{$e->getMessage()}\"}";
}

echo $json;
